/*
 *  Copright: 2008 Philipp Leitner, Distributed Systems Group,
 *            TU Wien, leitner@infosys.tuwien.ac.at
 *
 *  This file is part of DAIOS.
 *
 *  DAIOS is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as
 *  published by the Free Software Foundation.
 * 
 *  DAIOS is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with DAIOS.  If not, see
 *  <http://www.gnu.org/licenses/>.
 * 
 */

package at.ac.tuwien.infosys.dsg.daios.exceptions;

import java.util.Iterator;

import org.apache.axiom.om.OMElement;

/**
 * The SOAP using the native backend invocation came back with
 * Fault.
 * 
 * @author philipp
 *
 */
public class SOAPEncodedException extends Exception {
	
	private static final long serialVersionUID = 2773543142459698728L;

	private String faultcode = null;
	private String message = null;
	
	public SOAPEncodedException(OMElement fault) {
		
		Iterator children = fault.getChildElements();
		OMElement child = null;
		while(children.hasNext()) {
			child = (OMElement) children.next();
			if(child.getLocalName().equals("faultcode")) {
				faultcode = child.getText();
			}
			else if(child.getLocalName().equals("faultstring")) {
				message = child.getText();
			}
		}
		
	}
	
	public String getMessage() {
		return "Faultcode: "+faultcode+"\n"+message;
	}
	
}
